/*  
 * @(#) DemoAjaxUserActionb.java Create on 2012-5-11 上午11:43:21   
 *   
 * Copyright 2012 by xl.   
 */

package cn.com.demo.ajax.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.com.common.base.action.BaseAction;
import cn.com.demo.ajax.service.DemoAjaxUserService;
import cn.com.demo.bean.DemoUserBean;
import cn.tools.CommonSendMeg;

/**
 * ajax 例子
 * 
 * @author zhanghongliang
 * @date 2012-5-11
 */
@Controller
@Scope("prototype")
public class DemoAjaxUserAction extends BaseAction {
	private static final long serialVersionUID = 4478805292810173044L;

	@Resource
	DemoAjaxUserService service;

	/**
	 * 跳到主页面
	 * 
	 * @Title: toIndex
	 * @data:2012-5-11上午11:44:10
	 * @author:zhanghongliang
	 * 
	 * @return
	 */
	public String toIndex() {
		return TOINDEX;
	}

	/**
	 * 查询列表
	 * 
	 * @Title: query
	 * @data:2012-5-11下午12:19:45
	 * @author:zhanghongliang
	 * 
	 */
	public void query() throws Exception {
		String query = getFromRequestParameter("query");
		String msg = service.query(query);
		CommonSendMeg.writeMsg(ServletActionContext.getResponse(), msg);
	}

	public void find() throws Exception {
		String msg = this.service.find(oprBean);
		CommonSendMeg.writeMsg(ServletActionContext.getResponse(), msg);
	}

	public void save() throws Exception {
		String msg = this.service.save(oprBean);
		CommonSendMeg.writeMsg(ServletActionContext.getResponse(), msg);
//		return INPUT;
	}

	public void delete() throws Exception {
		String msg = this.service.delete(oprBean);
		CommonSendMeg.writeMsg(ServletActionContext.getResponse(), msg);
	}

	private DemoUserBean oprBean = new DemoUserBean();

	public DemoUserBean getOprBean() {
		return oprBean;
	}

	public void setOprBean(DemoUserBean oprBean) {
		this.oprBean = oprBean;
	}
}
